﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace SmartProject.BusinessObjects
{
    /// <summary>
    /// WorkAttachment is a helper class that wraps around the attachment
    /// class and provide support for some work that is required to get/ set
    /// the right attachments.
    /// </summary>
    public class WorkAttachment : Attachment
    {
        private int _referenceObjectId;

        /// <summary>
        /// Creates a new instance of the Work attachment class.
        /// </summary>
        public WorkAttachment()
        {
            AttachmentReferenceObject attachmentReferenceObject =
                new AttachmentReferenceObject();
            // Get work-related attachment reference object Id.
            _referenceObjectId = attachmentReferenceObject.GetId("Work", false);
        }

        /// <summary>
        /// Overriden method assist in Saving an attachment related to work.
        /// </summary>
        public override void Save()
        {
            base.SetAttribute("ReferenceObjectId", _referenceObjectId);
            base.Save();
        }

        /// <summary>
        /// Overriden method assist in removing all attachments related to work.
        /// </summary>
        public override void Remove()
        {
            base.SetAttribute("ReferenceObjectId", _referenceObjectId);
            base.Run("smartProject_RemoveReferenceObjectAttachments");
        }

        public void Populate(System.Web.UI.WebControls.ListControl listControl)
        {

        }

        public System.Data.DataTable LoadAttachments()
        {
            base.SetAttribute("ReferenceObjectId", _referenceObjectId);
            return base.Find("smartProject_GetReferenceObjectAttachments");
        }
    }
}
